package com.tianqu.tms.www.car.action;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.MarketCarInfoTemp;
import com.tianqu.tms.www.car.controller.CarInformationCollectListController;
import com.tianqu.tms.www.car.viewhelper.CarCreationInputViewHelper;

/**
 * @author mufeiyu
 * 车辆采集列表action
 */
public class CarInformationCollectListAction extends TmsAction{
	private Logger logger = Logger.getLogger(CarInformationCollectListAction.class);
	public final static String PAGENO = "pageNo";
	public final static String SORTKEY = "sortKey";
	public final static String MAXINDEX = "maxIndex";
	public final static String ASC = "asc";
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");

		CarCreationInputViewHelper view = new CarCreationInputViewHelper();
		if(request.getParameter(PAGENO) == null) {
			uc.setAttribute(PAGENO, view.getPageNo());
			uc.setAttribute(SORTKEY, "6");
			uc.setAttribute(MAXINDEX, "50");
			uc.setAttribute(ASC, "false");
		} else {
			uc.setAttribute(PAGENO, request.getParameter(PAGENO));
			uc.setAttribute(SORTKEY, request.getParameter(SORTKEY));
			uc.setAttribute(MAXINDEX, request.getParameter(MAXINDEX));
			uc.setAttribute(ASC, request.getParameter(ASC));
		}
		CarInformationCollectListController controller = new CarInformationCollectListController();
		controller.execute(uc);
		view.setPadList((List)uc.getAttribute(TmsConstants.VIEWHELP));
		MarketCarInfoTemp carInfoTemp = (MarketCarInfoTemp)uc.getAttribute(CarInformationCollectListController.PAGING);
		// viewhelp中设置翻页。
		view.setPageNo(Integer.toString(carInfoTemp.getPageNo()));
		view.setMaxIndex(Integer.toString(carInfoTemp.getMaxIndex()));
		view.setAsc(Boolean.toString(carInfoTemp.isAsc()));
		view.setSortKey(Integer.toString(carInfoTemp.getSortKey()));
		view.setTotalCount(Integer.toString(carInfoTemp.getTotalCount()));
		view.setDateFrom(Integer.toString(carInfoTemp.getDateFrom()));
		view.setDateTo(Integer.toString(carInfoTemp.getDateTo()));
		uc.setAttribute("carInformationList", view);
		request.setAttribute(TmsConstants.VIEWHELP, view);//直接把list打到前台

		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);	
	}

}
